package com.dotflat.staffExtend.domain;

import com.dotflat.rest.domain.AreableObjectBase;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;
import java.util.UUID;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/13
 * *******************************
 */
@Entity
@Data
@Table(name = "ex_staff_extend_career" )
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class StaffExtendCareer extends AreableObjectBase {

    @Column(columnDefinition = "varchar(32)  COMMENT '扩展记录id'")
    private String extendInfoId;

    @ManyToOne
    @JoinColumn(name = "extendInfoId", columnDefinition = "varchar(32) COMMENT '扩展记录id'", insertable = false, updatable = false)
    @JsonIgnore
    private StaffExtendInfo staffExtendInfo;

    @Column(columnDefinition = "datetime default NOW() COMMENT '开始时间'", nullable = false)
    private Date beginDate = new Date();

    @Column(columnDefinition = "datetime default NOW() COMMENT '结束时间'", nullable = false)
    private Date endDate = new Date();

    @Column(columnDefinition = "varchar(512)  COMMENT '描述'")
    private String description;

    @Column(columnDefinition = "varchar(512)  COMMENT '扩展字段，暂时放classId'")
    private String reserved;

    @Transient
    private String areaName;

    @Transient
    private String staffId;

    @Transient
    private String staffName;

    public static StaffExtendCareer of(String areaId,String createdBy,String staffId, String description){
        StaffExtendCareer log = new StaffExtendCareer();
        //没ID异常，莫名其妙
        log.setId( UUID.randomUUID().toString().replaceAll("-", "").substring(0, 32));
        log.setExtendInfoId(staffId);
        log.setCreatedBy(createdBy);
        log.setDescription(description);
        log.setAreaId(areaId);
        return log;
    }
}
